<?php get_header(); ?>

<script>
  $(document).ready(function(){
    $('#smart-archives-block').before('<div class="year-list"><ul><li class="active"></li></ul></div>');
  
    // get year
    $('#smart-archives-block li').each(function(){
      var str = $(this).find('strong a').text();
      $('.year-list ul').append('<li>'+str+'</li>');
      $(this).find('strong').hide();
    });
    
    var t = $('.year-list ul li:nth-child(2)').text();
    $('.year-list ul li:nth-child(2)').addClass('hide');
    $('.year-list ul li:nth-child(1)').text(t);
    $('.year-list ul li:nth-child(1)').append('<img class="year-arrow" src="<?php bloginfo('template_url'); ?>/images/blog-arrow.png" />');
    
    $('.year-list li').click(function(){
      var n = $(this).index();
      if(n < 1){ n = 1; }
      $('#smart-archives-block li').hide();
      $('#smart-archives-block li:nth-child('+(n)+')').show();
      
      var text = $(this).text();
      $('.year-list ul li:nth-child(1)').text(text).append('<img class="year-arrow" src="<?php bloginfo('template_url'); ?>/images/blog-arrow.png" />');
      
      $('.year-list li:nth-child(n+2)').hide();
    });
    
    $('.year-list').hover(function(){
      var el = $(this).find('li');
      el.removeClass('hide');
      
      if(el.text == $('.year-list ul li:nth-child(1)').text()){
        el.addClass('hide');
      }
      
      $(this).find('li').show();
    },function(){
      $(this).find('li:not(.active)').hide();
    });
    
    var str = $('.blog-desc p').text();
    global = str;
    $('.blog-desc p').html('<b>'+str[0]+'</b>'+str.substr(1, str.length-1));
    // console.log(str.length);
  });
</script>

<?php setPostViews(get_the_ID()); ?>

<div class="blog detail">
  <div class="blog-nav">
    <div class="blog-nav-container">
      <span class="title">ARCHIEVE</span>
      
      <?php
        $sar_args = array(
          'format' => 'block',
        );

        $query_args = array(
          'post_type' => 'post',
          'category__in' => array(3)
        );

        smart_archives( $sar_args, $query_args );
      ?>
    </div>
  </div>

  <div class="container">
  
    <div class="blog-header">
      <div class="blog-date">
        <div class="round">
          <h1><?php echo strftime('%d',strtotime($post->post_date)); ?></h1>
          <h2><?php echo strftime('%b',strtotime($post->post_date)); ?></h2>
        </div>
      </div>
      <div class="blog-title">
        <span></span>
        <h3 style="margin-top: -5px;"><?php the_field('subtitle',$post->ID); ?></h3>
        <h1><?php echo $post->post_title; ?></h1>
        <h3><?php the_field('client',$post->ID); ?></h3>
      </div>
      <div class="blog-views">
        <div class="round">
          <h1><?php echo getPostViews($post->ID); ?></h1>
          <h2>views</h2>
        </div>
      </div>
      <div class="clear"></div>
    </div>
    <div class="blog-content">
      <div class="detail-content blog-pic">
        <?php
          $attachments = attachments_get_attachments();
          if ($attachments) {
          foreach($attachments as $attachment){
        ?>
        <img src="<?php echo $attachment['location'] ?>" class="bx-shadow" />
        <?php }} ?>
        <div class="separator"></div>
          <div class="blog-desc">
            <?php echo wpautop($post->post_content); ?>
          </div>
      </div>
    </div>
    <div class="blog-footer">
      <div class="blog-footer-container">
        <div class="prev-nav">
          <?php previous_post('%','&laquo; Previous', 'no', '1'); ?> 
        </div>
        <div class="social">
          <?php echo do_shortcode('[wpsr_facebook]'); ?>
          <?php echo do_shortcode('[wpsr_retweet]'); ?>
          <?php echo do_shortcode('[wpsr_plusone]'); ?>
        </div>
        <div class="next-nav">
          <?php next_post('%','Next &raquo;', 'no', '1'); ?> 
        </div>
      </div>
    </div>
    <div class="blog-comments">
      <?php comments_template(); ?>
    </div>
  </div>
</div>

<?php get_footer(); ?>